package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.FinanceDao;
import cn.itcast.domain.cargo.Finance;
import cn.itcast.domain.cargo.FinanceExample;
import cn.itcast.service.cargo.FinanceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;
import java.util.UUID;


@Service
public class FinanceServiceImpl implements FinanceService {

    @Autowired
    private FinanceDao financeDao;


    @Override
    public PageInfo<Finance> findByPage(FinanceExample financeExample, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum,pageSize);
        List<Finance> financeList = financeDao.selectByExample(financeExample);
        PageInfo<Finance> pageInfo = new PageInfo<>(financeList);

        return pageInfo;
    }

    @Override
    public List<Finance> findAll(FinanceExample financeExample) {
        return financeDao.selectByExample(financeExample);
    }

    @Override
    public Finance findById(String id) {
        return financeDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Finance finance) {
        finance.setCreateTime(new Date());
        finance.setFinanceId(UUID.randomUUID().toString());

        financeDao.insertSelective(finance);
    }

    @Override
    public void update(Finance finance) {

        financeDao.updateByPrimaryKeySelective(finance);
    }

    @Override
    public void delete(String id) {

        financeDao.deleteByPrimaryKey(id);

    }
}
